/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package post.ui;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 *
 * @author Harry
 */
public class Ui {

    //I have tried to keep the UI independent from other classes as much as possible!
    public static String showMenu() {
        String str = "";
        try {
            System.out.println("Commands:");
            System.out.println("1- Add transaction.");
            System.out.println("2- Add product.");
            System.out.println("3- Get product info by upc.");
            System.out.println("4- Print all products and their details.");
            System.out.println("5- Print all transactions ordering by date.");
            System.out.println("6- Print all transactions by customer.");
            System.out.println("7- Close store.");
            System.out.print("Please enter command number: ");

            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            str = br.readLine();
        } catch (Exception e) {
            System.out.println("ERROR!" + e.toString());
        }
        return str;
    }

    public static void addProduct(String[] outputArray) {
        try {
            System.out.print("Please enter product description: ");
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            outputArray[0] = br.readLine();
            System.out.print("Please enter product upc: ");
            outputArray[1] = br.readLine();
            System.out.print("Please enter product price: ");
            outputArray[2] = br.readLine();

        } catch (Exception e) {
            System.out.println("ERROR!" + e.toString());
        }
    }

    public static String getCustomerName() {
        String str = "";
        try {
            System.out.print("Please enter customer name: ");
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            str = br.readLine();

        } catch (Exception e) {
            System.out.println("ERROR!" + e.toString());
        }
        return str;

    }

    public static int getTransactionItems(String[] outputArray, String[] outputArray2) {
        String str;
        int i;
        System.out.println("Please enter product upc (enter 0 to finish): ");
        for (i = 0; i < 100; i++) {
            try {
                System.out.print("Upc: ");
                InputStreamReader isr = new InputStreamReader(System.in);
                BufferedReader br = new BufferedReader(isr);
                str = br.readLine();
                if (str.equals("0")) {
                    break;
                } else {
                    outputArray[i] = str;
                }
                System.out.print("Quantity: ");
                outputArray2[i] = br.readLine();

            } catch (Exception e) {
                System.out.println("ERROR!" + e.toString());
            }
        }
        return i;
    }

    public static String getPaymentType() {
        String str = "";
        try {
            System.out.println("Payments: ");
            System.out.println("1- Cash.");
            System.out.println("2- Cheque.");
            System.out.println("3- Credit Card.");
            System.out.print("Please enter payment type number: ");
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            str = br.readLine();

        } catch (Exception e) {
            System.out.println("ERROR!" + e.toString());
        }
        return str;
    }

    public static void invalidCommand() {
        System.out.println("Invalid Command!!");
    }

    public static void printInvoice(String argInvoice) {
        System.out.println(argInvoice);
    }

    public static String getUpc() {
        String upc = "";
        try {
            System.out.print("Please enter product upc: ");
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            upc = br.readLine();

        } catch (Exception e) {
            System.out.println("ERROR!" + e.toString());
        }
        return upc;
    }

    public static void printProductInfo(String[] strArray) {
        System.out.println("Product info:");
        System.out.println("upc: " + strArray[0]);
        System.out.println("Description: " + strArray[1]);
        System.out.println("Price: " + strArray[2]);
    }

    public static float getCashTendered() {
        float cash=0;
        try {
            System.out.print("Please enter amount received: ");
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            cash = Float.parseFloat(br.readLine());

        } catch (Exception e) {
            System.out.println("ERROR!" + e.toString());
        }
        return cash;
    }

    public static int getCreditCardNum() {
        int ccNum=0;
        try {
            System.out.print("Please enter Credit Card Number: ");
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            ccNum = Integer.parseInt(br.readLine());

        } catch (Exception e) {
            System.out.println("ERROR!" + e.toString());
        }
        return ccNum;
    }
}
